package com.xbb.kafka.producer;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;

import java.util.Properties;

public class MyProducer {
  public static void main(String[] args) {

    Properties properties = new Properties();
    // --broker-list
    properties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "hadoop1:9092");
    properties.put(ProducerConfig.ACKS_CONFIG, "-1");
    properties.put("retries", 3);
    properties.put("batch.size", 16384);
    properties.put("linger.ms", 1);
    properties.put("buffer.memory", 33554432);
    properties.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
    properties.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");

    KafkaProducer<String, String> producer = new KafkaProducer<>(properties);

    for (int i = 0; i < 10; i++) {
      producer.send(new ProducerRecord<>(
              "top",
              "Message--" + i + "--" + System.currentTimeMillis()
      ));
    }

    producer.close();

  }
}
